package com.txy.domain.strategy.service.rule.tree.impl;

import com.txy.domain.strategy.model.vo.RuleLogicCheckTypeVO;
import com.txy.domain.strategy.repository.IStrategyRepository;
import com.txy.domain.strategy.service.rule.tree.ILogicTreeNode;
import com.txy.domain.strategy.service.rule.tree.factory.DefaultTreeFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component("rule_lock")
public class RuleLockLogicTreeNode implements ILogicTreeNode {
    public Integer userRaffleCount = 200;

    @Override
    public DefaultTreeFactory.DecisionEngineRes logic(Long strategyId, String userId, Integer awardId, String ruleValue) {

        log.info("规则过滤-规则树-rule_lock开始: strategyId={}, userId={}", strategyId, userId);
        int ruleLockCount = Integer.parseInt(ruleValue);
        // 如果抽奖次数达到解锁次数 继续执行，否则返回幸运奖
        if (ruleLockCount <= userRaffleCount) {
            log.info("规则过滤-规则树-rule_lock放行: strategyId={}, userId={}", strategyId, userId);
            return DefaultTreeFactory.DecisionEngineRes.builder()
                    .ruleLogicCheckTypeVO(RuleLogicCheckTypeVO.ALLOW).build();
        }
        // 返回幸运奖
        log.info("规则过滤-规则树-rule_lock接管: strategyId={}, userId={}", strategyId, userId);
        return DefaultTreeFactory.DecisionEngineRes.builder()
                .ruleLogicCheckTypeVO(RuleLogicCheckTypeVO.TAKE_OVER).build();
    }
}
